package com.array;
//数组的声明与创建
public class Demo01 {
    public static void main(String[] args) {
        //动态初始化：包含默认初始值
        int[] nums = new int[3];
        nums[0] = 1;
        nums[1] = 2;
        System.out.println(nums[1]);
        System.out.println(nums[2]);

        //静态初始化：创建+赋值
        int[] a = {4, 5, 6};
        System.out.println(a[2]);

        //求和
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum = sum + nums[i];
        }
        System.out.println(sum);

        //数组下标越界 ArrayIndexOutOfBoundsException
        int sum1 = 0;
        for (int i = 0; i <= nums.length; i++) {
            sum1 = sum1 + nums[i];
        }
        System.out.println(sum1);
    }
}
